home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr11 / pd0836.zip / DRVINFO.C < prev    next >
C/C++ Source or Header  |  1993-04-30  |  7KB  |  182 lines

  1. /***    DRVINFO.C - IsDoubleSpaceDrive function
  2.  *
  3.  *      Version 1.00.58  12-Mar-1993
  4.  */
  5.  
  6. #include "drvinfo.h"
  7.  
  8. #pragma pack(1)
  9.  
  10. /** DSPACKET - IOCTL packet definition for DoubleSpace API IOCtls
  11.  *
  12.  */
  13. typedef struct DSPACKET_t { /* dsp */
  14.     WORD    stamp;                      // Identifying stamp ('DM')
  15.     BYTE    command;                    // Command ('F' or 'I')
  16.     WORD    result;                     // Result code ('OK', else unmodified)
  17.     BYTE    abPadding[5];               // Padding
  18. } DSPACKET;
  19. #define cbDSPACKET  10                  // sizeof(DSPACKET), for ASM code
  20.  
  21. #define MD_STAMP    (('D'<<8) + 'M')    // dsp.stamp value
  22.  
  23. #define DSCMD_FLUSH                 'F' // dsp.command for Flush
  24. #define DSCMD_FLUSH_AND_INVALIDATE  'I' // dsp.command for Flush & Invalidate
  25.  
  26. #define DSP_NO_ERROR    ('O'<<8 + 'K')  // Success value for dsp.result
  27. #define DSP_ERROR       ('?'<<8 + '?')  // Initial value for dsp.result
  28.  
  29.  
  30.  
  31. /***    IsDoubleSpaceDrive - Get information on a DoubleSpace drive
  32.  *
  33.  *      Entry:
  34.  *          drive     - Drive to test (0=A, 1=B, etc.)
  35.  *                      NOTE: No parameter checking is done on drive.
  36.  *          pdrHost   - Receives drive number of host drive
  37.  *          pfSwapped - Receives TRUE/FALSE indicating if drive is swapped.
  38.  *          pseq      - Receives CVFs sequence number if DoubleSpace drive
  39.  *
  40.  *      Exit:
  41.  *          returns TRUE, if DoubleSpace drive:
  42.  *              *pdrHost   = current drive number of host drive (0=A,...)
  43.  *              *pfSwapped = TRUE, if drive is swapped with host,
  44.  *                           FALSE, if drive is not swapped with host
  45.  *              *pseq      = CVF sequence number (always zero if swapped
  46.  *                             with host drive)
  47.  *
  48.  *                           NOTE: The full file name of the CVF is:
  49.  *                                   *pdrHost:\DBLSPACE.*pseq
  50.  *
  51.  *                               pdrHost  pseq  Full Path
  52.  *                               -------  ----  -----------
  53.  *                                  0       1   a:\dblspace.001
  54.  *                                  3       0   d:\dblspace.000
  55.  *
  56.  *          returns FALSE, if *not* DoubleSpace drive:
  57.  *              *pdrHost   = drive number of host drive at boot time
  58.  *              *pfSwapped = TRUE, if swapped with a DoubleSpace drive
  59.  *                           FALSE, if not swapped with a DoubleSpace drive
  60.  */
  61. BOOL IsDoubleSpaceDrive(BYTE drive, BOOL *pfSwapped, BYTE *pdrHost, int *pseq)
  62. {
  63.     BYTE        seq;
  64.     BYTE        drHost;
  65.     BOOL        fSwapped;
  66.     BOOL        fDoubleSpace;
  67.  
  68.     // Assume drive is a normal, non-host drive
  69.     drHost = drive;
  70.     fSwapped = FALSE;
  71.     fDoubleSpace = FALSE;
  72.     seq = 0;
  73.  
  74.     _asm {
  75.  
  76.         mov     ax,4A11h        ; DBLSPACE.BIN INT 2F number
  77.         mov     bx,1            ; bx = GetDriveMap function
  78.         mov     dl,drive        ;
  79.         int     2Fh             ; (bl AND 80h) == DS drive flag
  80.                                 ; (bl AND 7Fh) == host drive
  81.  
  82.         or      ax,ax           ; Success?
  83.         jnz     gdiExit         ;    NO, DoubleSpace not installed
  84.  
  85.         test    bl,80h          ; Is the drive compressed?
  86.         jz      gdiHost         ;    NO, could be host drive
  87.  
  88.         ; We have a DoubleSpace Drive, need to figure out host drive.
  89.         ;
  90.         ; This is tricky because of the manner in which DBLSPACE.BIN
  91.         ; keeps track of drives.
  92.         ;
  93.         ; For a swapped CVF, the current drive number of the host
  94.         ; drive is returned by the first GetDriveMap call.  But for
  95.         ; an unswapped CVF, we must make a second GetDriveMap call
  96.         ; on the "host" drive returned by the first call.  But, to
  97.         ; distinguish between swapped and unswapped CVFs, we must
  98.         ; make both of these calls.  So, we make them, and then check
  99.         ; the results.
  100.  
  101.         mov     fDoubleSpace,TRUE ; Drive is DS drive
  102.         mov     seq,bh          ; Save sequence number
  103.  
  104.         and     bl,7Fh          ; bl = "host" drive number
  105.         mov     drHost,bl       ; Save 1st host drive
  106.         mov     dl,bl           ; Set up for query of "host" drive
  107.  
  108.         mov     ax,4A11h        ; DBLSPACE.BIN INT 2F number
  109.         mov     bx,1            ; bx = GetDriveMap function
  110.         int     2Fh             ; (bl AND 7Fh) == 2nd host drive
  111.  
  112.         and     bl,7Fh          ; bl = 2nd host drive
  113.         cmp     bl,drive        ; Is host of host of drive itself?
  114.         mov     fSwapped,TRUE   ; Assume CVF is swapped
  115.         je      gdiExit         ;   YES, CVF is swapped
  116.  
  117.         mov     fSwapped,FALSE  ;   NO, CVF is not swapped
  118.         mov     drHost,bl       ; True host is 2nd host drive
  119.         jmp     short gdiExit
  120.  
  121.     gdiHost:
  122.         and     bl,7Fh          ; bl = host drive number
  123.         cmp     bl,dl           ; Is drive swapped?
  124.         je      gdiExit         ;    NO
  125.  
  126.         mov     fSwapped,TRUE   ;    YES
  127.         mov     drHost,bl       ; Set boot drive number
  128.  
  129.     gdiExit:
  130.     }
  131.  
  132.     *pdrHost   = drHost;
  133.     *pfSwapped = fSwapped;
  134.     *pseq      = seq;
  135.     return fDoubleSpace;
  136. }
  137.  
  138.  
  139. /***    FlushDrive - Flush buffers for DoubleSpace drive
  140.  *
  141.  *      Entry:
  142.  *          drive - Drive to flush (0=A, 1=B, etc.)
  143.  *          fdop  - Additional operations (invalidate and/or disk reset)
  144.  *
  145.  *      Exit-Success:
  146.  *          Returns TRUE.
  147.  *
  148.  *      Exit-Failure:
  149.  *          Returns FALSE.
  150.  *              Drive was not a DoubleSpace drive.
  151.  */
  152. BOOL FlushDrive(int drive, FDOP fdop)
  153. {
  154.     static DSPACKET dsp;
  155.     BYTE            bDrive = (BYTE)drive;
  156.  
  157.     dsp.stamp   = MD_STAMP;         // Set stamp
  158.     dsp.result  = DSP_ERROR;        // Init result code to assume error
  159.  
  160.     if (fdop & FDOP_INVALIDATE)
  161.         dsp.command = DSCMD_FLUSH_AND_INVALIDATE; // Flush command
  162.     else
  163.         dsp.command = DSCMD_FLUSH;      // Flush command
  164.  
  165.     if (fdop & FDOP_DISK_RESET)
  166.         _asm {
  167.         MOV     ax,0Dh              ; Disk reset
  168.         INT     21
  169.         }
  170.  
  171.     _asm {
  172.         MOV     AX,4404h            ; IOCtl read command
  173.         MOV     BL,bDrive           ; drive letter (0-based)
  174.         INC     BL                  ; drive letter (1-based)
  175.         MOV     CX,cbDSPACKET       ; packet length
  176.         MOV     DX,OFFSET dsp       ; ds:dx = IOCTL packet
  177.         INT     21h                 ; Flush DoubleSpace drive
  178.     }
  179.  
  180.     return (dsp.result == DSP_NO_ERROR);
  181. }
  182.